package com.lcredu.seckill.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.HeadersExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;

/**
 * @author 黎长容
 * @date 2025-09-06 15:14
 */
@Configuration
public class RabbitMQConfigHeaders {
    public static final String QUEUE_HEADER01 = "QUEUE_HEADER01";
    public static final String QUEUE_HEADER02 = "QUEUE_HEADER02";

    public static final String HEADER_EXCHANGE = "HEADER_EXCHANGE";

    //创建队列
    @Bean
    public Queue queue_header01() {
        return new Queue(QUEUE_HEADER01);
    }


    @Bean
    public Queue queue_header02() {
        return new Queue(QUEUE_HEADER02);
    }

    //创建交换机
    @Bean
    public HeadersExchange headersExchange() {
        return new HeadersExchange(HEADER_EXCHANGE);
    }

    //绑定
    @Bean
    public Binding headerBinding01() {
        //放置k-v
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("name", "lcredu");
        hashMap.put("color", "blue");
        return BindingBuilder.bind(queue_header01()).to(headersExchange()).whereAny(hashMap).match();
    }

    @Bean
    public Binding headerBinding02() {
        //放置k-v
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("name", "lcredu");
        hashMap.put("color", "red");
        return BindingBuilder.bind(queue_header02()).to(headersExchange()).whereAll(hashMap).match();
    }
}

